public class Test {
    public static void main(String[] args) {
        int[] arr = {-1,-1,0,1,1,-1};
        pivotIndex(arr);
    }
    //724.寻找数组的中心下标
    public static int pivotIndex(int[] nums) {
        int n = nums.length;
        int[] dp = new int[n+1];
        //dp[0]=0;

        for(int i=1;i<n+1;i++) dp[i] =dp[i-1]+nums[i-1];
        if(dp[n]-dp[1]==0) return 0;
        for(int i=1;i<n-1;i++) {
            if(dp[i] == dp[n]-dp[i+1])   return i;
        }
        if(dp[n-1]==0) return n-1;


        return -1;
    }


}
